package constant.milk.cashbook.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import constant.milk.cashbook.R;
import constant.milk.cashbook.bean.AutoMainData;
import constant.milk.cashbook.bean.BankData;
import constant.milk.cashbook.bean.CheckData;
import constant.milk.cashbook.bean.CreditData;
import constant.milk.cashbook.bean.GiftData;
import constant.milk.cashbook.bean.HalbuData;
import constant.milk.cashbook.bean.InOutData;
import constant.milk.cashbook.bean.MainSettingData;
import constant.milk.cashbook.bean.PhoneData;
import constant.milk.cashbook.bean.RealData;
import constant.milk.cashbook.bean.SmsData;
import constant.milk.cashbook.database.DBSelectQuery;
import constant.milk.cashbook.database.DbAdapter;
import constant.milk.cashbook.database.DbDeleteQuery;
import constant.milk.cashbook.database.DbUpdateQuery;
import constant.milk.cashbook.insert.InsertActivity;
import constant.milk.cashbook.insert.InsertFanActivity;

import android.content.Context;

public class MilkManager
{
	private Context context;
	private DbAdapter db;
	
	public MilkManager(Context context, DbAdapter db)
	{
		this.context = context;
		this.db = db;
	}
	
	/**
	 * 금액에서 뺀다. = 0 금액에서 더한다. = 1
	 * 신용카드와 핸드폰은 반대임. 상품권은 orgMoney 가 갯수임.
	 * @param context
	 * @param db
	 * @param asset 자산이름으로 들어와야함 숫자 안됨.
	 * @param name
	 * @param strMoney
	 * @param flag
	 * @throws Exception
	 */
	public void setAssetMoney(String asset, String name, String orgMoney, int flag) throws Exception
	{
		DBSelectQuery query = new DBSelectQuery(context, db);
		DbUpdateQuery updateQuery = new DbUpdateQuery(context, db);
		String strMoney = MilkUtil.getCommaDel(orgMoney);
		
		if (asset.equals(context.getString(R.string.realAsset)))
		{
			RealData data = query.getRealName(name);
			BigDecimal money = new BigDecimal(data.getMoney());
			
			if (flag == 0)
			{
				money = money.subtract(new BigDecimal(strMoney));
			}
			else
			{
				money = money.add(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("money", money.toString());
			updateQuery.setRealMoneyUpdate(map, data.getId());
		}
		else if (asset.equals(context.getString(R.string.bankAsset)))
		{
			BankData data = query.getBankName(name);
			BigDecimal money = new BigDecimal(data.getMoney());
			
			if (flag == 0)
			{
				money = money.subtract(new BigDecimal(strMoney));
			}
			else
			{
				money = money.add(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("money", money.toString());
			updateQuery.setBankBookUpdate(map, data.getId());
		}
		else if (asset.equals(context.getString(R.string.checkCardAsset)))
		{
			CheckData data = query.getCheckName(name);
			BankData bankData = query.getBankId(data.getLinkid());
			BigDecimal money = new BigDecimal(bankData.getMoney());
			
			if (flag == 0)
			{
				money = money.subtract(new BigDecimal(strMoney));
			}
			else
			{
				money = money.add(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("money", money.toString());
			updateQuery.setBankBookUpdate(map, bankData.getId());
		}
		else if (asset.equals(context.getString(R.string.creditCardAsset)))
		{
			CreditData data = query.getCreditName(name);
			BigDecimal money = new BigDecimal(data.getMoney());
			
			if (flag == 0)
			{
				money = money.add(new BigDecimal(strMoney));
			}
			else
			{
				money = money.subtract(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("money", money.toString());
			updateQuery.setCreditCardUpdate(map, data.getId());
		}
		else if (asset.toString().equals(context.getString(R.string.phoneAsset)))
		{
			PhoneData data = query.getPhoneName(name);
			BigDecimal money = new BigDecimal(data.getMoney());
			
			if (flag == 0)
			{
				money = money.add(new BigDecimal(strMoney));
			}
			else
			{
				money = money.subtract(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("money", money.toString());
			updateQuery.setPhoneUpdate(map, data.getId());
		}
		else if (asset.toString().equals(context.getString(R.string.giftCardAsset)))
		{
			GiftData data = query.getGiftName(name);
			BigDecimal number = new BigDecimal(data.getNumber());
			
			if (flag == 0)
			{
				number = number.subtract(new BigDecimal(strMoney)); 
			}
			else
			{
				number = number.add(new BigDecimal(strMoney));
			}
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("giftnumber", number.toString());
			updateQuery.setGiftCardUpdate(map, data.getId());
		}
	}
	
	/**
	 * 자산타입에 맞는 자산을 리턴 시킨다.
	 * 0 = 현금, 1 = 통장, 2 = 체크, 3 = 신용, 4 = 핸드폰, 5 = 상품권, 6 = 전체
	 * @param asset
	 * @return 현금, 통장, 체크, 신용, 핸드폰, 상품권, 전체
	 */
	public String getAssetId(String asset)
	{
		if (asset.equals("0"))
		{
			return context.getString(R.string.realAsset);
		}
		else if (asset.equals("1"))
		{
			return context.getString(R.string.bankAsset);
		}
		else if (asset.equals("2"))
		{
			return context.getString(R.string.checkCardAsset);
		}
		else if (asset.equals("3"))
		{
			return context.getString(R.string.creditCardAsset);
		}
		else if (asset.equals("4"))
		{
			return context.getString(R.string.phoneAsset);
		}
		else if (asset.equals("5"))
		{
			return context.getString(R.string.giftCardAsset);
		}
		else if (asset.equals("6"))
		{
			return context.getString(R.string.all);
		}
		
		return InsertActivity.REALMONEY;
	}
	
	/**
	 * 자산타입에 맞는 자산을 리턴 시킨다.
	 * 0 = 현금, 1 = 통장, 2 = 체크, 3 = 신용, 4 = 핸드폰, 5 = 상품권, 6= 전체
	 * @param asset
	 * @return 0, 1, 2, 3, 4, 5, 6
	 */
	public String getAssetStr(String asset)
	{
		if (asset.equals(context.getString(R.string.realAsset)))
		{
			return InsertActivity.REALMONEY;
		}
		else if (asset.equals(context.getString(R.string.bankAsset)))
		{
			return InsertActivity.BANKBOOK;
		}
		else if (asset.equals(context.getString(R.string.checkCardAsset)))
		{
			return InsertActivity.CHECKCARD;
		}
		else if (asset.equals(context.getString(R.string.creditCardAsset)))
		{
			return InsertActivity.CREDITCARD;
		}
		else if (asset.equals(context.getString(R.string.phoneAsset)))
		{
			return InsertActivity.PHONE;
		}
		else if (asset.equals(context.getString(R.string.giftCardAsset)))
		{
			return InsertActivity.GIFTCARD;
		}
		else if (asset.equals(context.getString(R.string.all)))
		{
			return "6";
		}
		
		return InsertActivity.REALMONEY;
	}
	
	/**
	 * 부채 타입에 맞는 텍스트를 반환한다.
	 * @param type
	 * @return 1 = 빌림, 2 = 빌려줌, 3 = 갚음, 4 = 받음
	 */
	public String getFanTypeId(String type)
	{
		if (type.equals("1"))
		{
			return context.getString(R.string.fanIn);
		}
		else if (type.equals("2"))
		{
			return context.getString(R.string.fanOut);
		}
		else if (type.equals("3"))
		{
			return context.getString(R.string.fanReturn);
		}
		else if (type.equals("4"))
		{
			return context.getString(R.string.fanReceive);
		}
		
		return InsertActivity.REALMONEY;
	}
	
	/**
	 * 부채 타입 이름에 맞는 번호를 반환한다.
	 * @param type
	 * @return 빌림 = 1, 빌려줌 = 2, 갚음 = 3, 받음 = 4
	 */
	public String getFanTypeStr(String type)
	{
		if (type.equals(context.getString(R.string.fanIn)))
		{
			return "1";
		}
		else if (type.equals(context.getString(R.string.fanOut)))
		{
			return "2";
		}
		else if (type.equals(context.getString(R.string.fanReturn)))
		{
			return "3";
		}
		else if (type.equals(context.getString(R.string.fanReceive)))
		{
			return "4";
		}
		
		return "1";
	}
	
	public String getWeekdayStr(String str)
	{
		String weekday = "일";
		
		if (str.equals(Calendar.SUNDAY + ""))
		{
			weekday = "일";
		}
		else if (str.equals(Calendar.MONDAY + ""))
		{
			weekday = "월";
		}
		else if (str.equals(Calendar.TUESDAY + ""))
		{
			weekday = "화";
		}
		else if (str.equals(Calendar.WEDNESDAY + ""))
		{
			weekday = "수";
		}
		else if (str.equals(Calendar.THURSDAY + ""))
		{
			weekday = "목";
		}
		else if (str.equals(Calendar.FRIDAY + ""))
		{
			weekday = "금";
		}
		else if (str.equals(Calendar.SATURDAY + ""))
		{
			weekday = "토";
		}
		
		return weekday;
	}
	
	public String getWeekdayInt(String weekday)
	{
		int selectWeekday = 1;
		
		if (weekday.equals("일"))
		{
			selectWeekday = Calendar.SUNDAY;
		}
		else if (weekday.equals("월"))
		{
			selectWeekday = Calendar.MONDAY;
		}
		else if (weekday.equals("화"))
		{
			selectWeekday = Calendar.TUESDAY;
		}
		else if (weekday.equals("수"))
		{
			selectWeekday = Calendar.WEDNESDAY;
		}
		else if (weekday.equals("목"))
		{
			selectWeekday = Calendar.THURSDAY;
		}
		else if (weekday.equals("금"))
		{
			selectWeekday = Calendar.FRIDAY;
		}
		else if (weekday.equals("토"))
		{
			selectWeekday = Calendar.SATURDAY;
		}
		
		return selectWeekday + "";
	}
	
	public String getWeekday(String weekday)
	{
		int selectWeekday = 1;
		
		if (weekday.equals("일"))
		{
			selectWeekday = Calendar.SUNDAY;
		}
		else if (weekday.equals("월"))
		{
			selectWeekday = Calendar.MONDAY;
		}
		else if (weekday.equals("화"))
		{
			selectWeekday = Calendar.TUESDAY;
		}
		else if (weekday.equals("수"))
		{
			selectWeekday = Calendar.WEDNESDAY;
		}
		else if (weekday.equals("목"))
		{
			selectWeekday = Calendar.THURSDAY;
		}
		else if (weekday.equals("금"))
		{
			selectWeekday = Calendar.FRIDAY;
		}
		else if (weekday.equals("토"))
		{
			selectWeekday = Calendar.SATURDAY;
		}
		
		Calendar cal = Calendar.getInstance();
		int nowWeekday = cal.get(Calendar.DAY_OF_WEEK);
		
		selectWeekday = selectWeekday - nowWeekday;
		
		if (selectWeekday > 0)
		{
			cal.add(Calendar.DAY_OF_MONTH, selectWeekday - 7);
		}
		else
		{
			cal.add(Calendar.DAY_OF_MONTH, selectWeekday);
		}
		
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		
		return MilkUtil.getDateDB(year, month+1, day);
	}
	
	public String getMonth(String monthday)
	{
		Calendar cal = Calendar.getInstance();
		int day = cal.get(Calendar.DAY_OF_MONTH);
		
		if (day < Integer.parseInt(monthday))
		{
			cal.add(Calendar.MONTH, -1);
		}
		
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH);
		
		return MilkUtil.getDateDB(year, month+1, Integer.parseInt(monthday));
	}
	
	/**
	 * 결제일에 맞쳐서 사용기간을 반환한다.
	 * @param termdate 사용기간
	 * @param resultdate 결제일
	 * @return fristDate, lastDate
	 */
	public String [] getTermDate(String termdate, String resultdate)
	{
		String [] dates = new String[2];
		
		Calendar cal1 = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		int term1 = Integer.parseInt(termdate);
		int term2 = term1--;
		
		if (term1 > Integer.parseInt(resultdate))
		{
			cal1.add(Calendar.MONTH, -2);
			cal2.add(Calendar.MONTH, -1);
		}
		else
		{
			cal1.add(Calendar.MONTH, -1);
		}
		
		int year1 = cal1.get(Calendar.YEAR);
		int month1 = cal1.get(Calendar.MONTH);
		
		int year2 = cal2.get(Calendar.YEAR);
		int month2 = cal2.get(Calendar.MONTH);
		
		dates[0] = MilkUtil.getDateDB(year1, month1+1, term1);
		
		if (term1 < 2)
		{
			term2 = 31;
		}
		
		dates[1] = MilkUtil.getDateDB(year2, month2+1, term2);
		
		return dates;
	}
	
	/**
	 * 조회 테이블의 돈을 합해서 반환한다.
	 * asset 0 = 현금, 1 = 통장, 2 = 체크, 3 = 신용, 4 = 핸드폰, 5 = 상품권
	 * @param list
	 * @return
	 */
	public String getSumInOutMoney(ArrayList<InOutData> list, String asset)
	{
		BigDecimal money = BigDecimal.ZERO;
		
		for (int i = 0; i < list.size(); i++)
		{
			if (asset.equals("6"))
			{
				money = money.add(new BigDecimal(list.get(i).getMoney()));
				
				if (list.get(i).getKind().equals("6"))
				{
					money = money.add(new BigDecimal(list.get(i).getSubmoney()));
				}
				else if (list.get(i).getKind().equals("7"))
				{
					money = money.subtract(new BigDecimal(list.get(i).getSubmoney()));
				}
			}
			else if (list.get(i).getAsset().equals("5"))
			{
				if (list.get(i).getKind().equals("6"))
				{
					money = money.add(new BigDecimal(list.get(i).getSubmoney()));
				}
				else if (list.get(i).getKind().equals("7"))
				{
					money = money.subtract(new BigDecimal(list.get(i).getSubmoney()));
				}
				else if (list.get(i).getKind().equals("0"))
				{
					money = money.add(new BigDecimal(list.get(i).getMoney()));
				}
			}
			else
			{
				money = money.add(new BigDecimal(list.get(i).getMoney()));
			}
		}
		
		return money.toString();
	}
	
	/**
	 * 조회 테이블 지출 상품권의 돈을 합해서 반환한다.
	 * @param list
	 * @return
	 */
	public String getSumOutGiftCardMoney(ArrayList<InOutData> list)
	{
		BigDecimal money = BigDecimal.ZERO;
		
		for (int i = 0; i < list.size(); i++)
		{
			money = money.add(new BigDecimal(list.get(i).getMoney()));
		}
		
		return money.toString();
	}
	
	/**
	 * 조회 테이블의 돈을 합해서 반환한다.
	 * @param list
	 * @return
	 */
	public BigDecimal getSumInOutMoney(InOutData data, BigDecimal money)
	{
		money = money.add(new BigDecimal(data.getMoney()));
		
		if (data.getKind().equals("6"))
		{
			money = money.add(new BigDecimal(data.getSubmoney()));
		}
		else if (data.getKind().equals("7"))
		{
			money = money.subtract(new BigDecimal(data.getSubmoney()));
		}
		
		return money;
	}
	
	/**
	 * 자산타입에 맞는 자산을 리턴 시킨다.
	 * 0 = 지출, 1 = 수입, 2 = 이동, 4 = 잔액 
	 * @param asset
	 * @return 0, 1, 2, 4
	 */
	public String getMainStr(String type)
	{
		if (type.equals(context.getString(R.string.out)))
		{
			return "0";
		}
		else if (type.equals(context.getString(R.string.in)))
		{
			return "1";
		}
		else if (type.equals(context.getString(R.string.move)))
		{
			return "2";
		}
		else if (type.equals(context.getString(R.string.fan)))
		{
			return "3";
		}
		else if (type.equals(context.getString(R.string.balance)))
		{
			return "4";
		}
		
		return "0";
	}
	
	/**
	 * 자산타입에 맞는 자산을 리턴 시킨다.
	 * 0, 1, 2, 4
	 * @param asset
	 * @return 0 = 지출, 1 = 수입, 2 = 이동, 4 = 잔액
	 */
	public String getMainId(String str)
	{
		if (str.equals("0"))
		{
			return context.getString(R.string.out);
		}
		else if (str.equals("1"))
		{
			return context.getString(R.string.in);
		}
		else if (str.equals("2"))
		{
			return context.getString(R.string.move);
		}
		else if (str.equals("3"))
		{
			return context.getString(R.string.fan);
		}
		else if (str.equals("4"))
		{
			return context.getString(R.string.balance);
		}
		
		return context.getString(R.string.out);
	}
	
	/**
	 * 메인화면 부채에 대한 부분을 리턴한다.
	 * 0 = 빌림, 1 = 빌려줌, 2 = 갚음, 4 = 받음 
	 * @param asset
	 * @return 1, 2, 3, 4
	 */
	public String getMainFanStr(String kind)
	{
		if (kind.equals(context.getString(R.string.fanIn)))
		{
			return "1";
		}
		else if (kind.equals(context.getString(R.string.fanOut)))
		{
			return "2";
		}
		else if (kind.equals(context.getString(R.string.fanReturn)))
		{
			return "3";
		}
		else if (kind.equals(context.getString(R.string.fanReceive)))
		{
			return "4";
		}
		
		return "1";
	}
	
	/**
	 * 메인화면 부채에 대한 부분을 리턴한다.
	 * 0 = 빌림, 1 = 빌려줌, 2 = 갚음, 4 = 받음 
	 * @param asset
	 * @return 1, 2, 3, 4
	 */
	public String getMainFanId(String kind)
	{
		if (kind.equals("1"))
		{
			return context.getString(R.string.fanIn);
		}
		else if (kind.equals("2"))
		{
			return context.getString(R.string.fanOut);
		}
		else if (kind.equals("3"))
		{
			return context.getString(R.string.fanReturn);
		}
		else if (kind.equals("4"))
		{
			return context.getString(R.string.fanReceive);
		}
		
		return "1";
	}
	
	/**
	 * 엑셀테이터에 타입 형태를 반환한다.
	 * @param data
	 * @return 지출, 수입, 이동, 부채, 대금처리
	 */
	public String getExcelType(String type)
	{
		// type 0 = 지출, 1 = 수입, 2 = 이동, 3 = 부채, 4 = 신용카드, 5 = 소액결제, 6 = 상품권사용, 7 = 상품권구입, 8 = 대금처리
		if (type.equals("0"))
		{
			return context.getString(R.string.out);
		}
		else if (type.equals("1"))
		{
			return context.getString(R.string.in);
		}
		else if (type.equals("2"))
		{
			return context.getString(R.string.move);
		}
		else if (type.equals("3"))
		{
			return context.getString(R.string.fan);
		}
		else if (type.equals("4"))
		{
			return context.getString(R.string.out);
		}
		else if (type.equals("5"))
		{
			return context.getString(R.string.out);
		}
		else if (type.equals("6"))
		{
			return context.getString(R.string.out);
		}
		else if (type.equals("7"))
		{
			return context.getString(R.string.move);
		}
		else if (type.equals("8"))
		{
			return context.getString(R.string.creditPhoneMoney);
		}
		
		return context.getString(R.string.out);
	}
	
	/**
	 * 엑셀테이터에 맞는 종류 형태를 반환한다.
	 * @param kind
	 * @param type 6 = 상품권사용  7 = 상품권구입
	 * @return 일반, 빌림, 빌려줌, 갚음, 받음, 완불, 추가금액, 거스름돈
	 */
	public String getExcelKind(String kind, String type)
	{
		// kind 0 = 일반, 1 = 빌림,  2 = 빌려줌, 3 = 갚음, 4 = 받음, 5 = 완불, 6 = 추가금액, 7 = 거스름돈
		if (type.equals("6"))
		{
			return "상품권사용";
		}
		else if (type.equals("7"))
		{
			return "상품권구입";
		}
		else
		{
			if (kind.equals("0"))
			{
				return "일반";
			}
			else if (kind.equals("1"))
			{
				return "빌림";
			}
			else if (kind.equals("2"))
			{
				return "빌려줌";
			}
			else if (kind.equals("3"))
			{
				return "갚음";
			}
			else if (kind.equals("4"))
			{
				return "받음";
			}
			else if (kind.equals("5"))
			{
				return "완불";
			}
			else if (kind.equals("6"))
			{
				return "추가금액";
			}
			else if (kind.equals("7"))
			{
				return "거스름돈";
			}
		}
		
		return "일반";
	}
	
	/**
	 * 자산이 삭제 되었는지 판단해서 다이얼로그를 뛰워 준다.
	 * @param data
	 * @return
	 */
	public boolean checkAsset(InOutData data)
	{
		DBSelectQuery select = new DBSelectQuery(context, db);
		
		int count = 0;
		
		if (data.getAsset().equals("0"))
		{
			count = select.getRealCount(data.getName());
		}
		else if (data.getAsset().equals("1"))
		{
			count = select.getBankCount(data.getName());
		}
		else if (data.getAsset().equals("2"))
		{
			count = select.getCheckCount(data.getName());
		}
		else if (data.getAsset().equals("3"))
		{
			count = select.getCreditCount(data.getName());
		}
		else if (data.getAsset().equals("4"))
		{
			count = select.getPhoneCount(data.getName());
		}
		else if (data.getAsset().equals("5"))
		{
			count = select.getGiftCardCount(data.getName());
		}
		
		if (count < 1)
		{
			MilkUtil.showDialog(context, "확인", "내역의 자산을 찾을 수 없어서(삭제 되어서), 수정 및 삭제를 할 수가 없습니다. 자산을 같은 걸로 다시 만들어 주시면 가능합니다.");
			return false;
		}
		
		if (!data.getSubname().equals(""))
		{
			count = 0;
			
			if (data.getSubasset().equals("0"))
			{
				count = select.getRealCount(data.getSubname());
			}
			else if (data.getSubasset().equals("1"))
			{
				count = select.getBankCount(data.getSubname());
			}
			else if (data.getSubasset().equals("2"))
			{
				count = select.getCheckCount(data.getSubname());
			}
			else if (data.getSubasset().equals("3"))
			{
				count = select.getCreditCount(data.getSubname());
			}
			else if (data.getSubasset().equals("4"))
			{
				count = select.getPhoneCount(data.getSubname());
			}
			else if (data.getSubasset().equals("5"))
			{
				count = select.getGiftCardCount(data.getSubname());
			}
			
			if (count < 1)
			{
				MilkUtil.showDialog(context, "확인", "두번째 자산을 찾을 수 없어서(삭제 되어서), 수정 및 삭제를 할 수가 없습니다. 자산을 같은 걸로 다시 만들어 주시면 가능합니다.");
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * asset 0 = 현금, 1 = 통장, 2 = 체크, 3 = 신용, 4 = 핸드폰, 5 = 상품권
	 * @param asset
	 * @param name
	 * @throws Exception
	 */
	public void setDeleteAssetRollBank(String asset, String name) throws Exception
	{
		DBSelectQuery select = new DBSelectQuery(context, db);
		DbDeleteQuery delete = new DbDeleteQuery(context, db);
		
		ArrayList<MainSettingData> Mainlist = select.getMainSettingAssetToName(asset, name);
		
		for (int i = 0; i < Mainlist.size(); i++)
		{
			delete.setMainSettingDelete(Mainlist.get(i).getId());
		}
		
		ArrayList<AutoMainData> autoList = select.getAutoAssetList(asset, name);
		
		for (int i = 0; i < autoList.size(); i++)
		{
			delete.setAutoMainDelete(autoList.get(i).getId());
		}
		
		ArrayList<SmsData> smsList = select.getSmsAssetList(asset, name);
		
		for (int i = 0; i < smsList.size(); i++)
		{
			delete.setSmsDelete(smsList.get(i).getId());
		}
		
		ArrayList<HalbuData> halbuList = select.getHalbuAssetList(asset, name);
		
		for (int i = 0; i < halbuList.size(); i++)
		{
			delete.setSmsDelete(halbuList.get(i).getId());
		}
	}
	
	/**
	 * asset 0 = 현금, 1 = 통장, 2 = 체크, 3 = 신용, 4 = 핸드폰, 5 = 상품권
	 * @param asset
	 * @param name
	 * @throws Exception
	 */
	public void setUpdateAssetRollBank(String asset, String name, String newName) throws Exception
	{
		DBSelectQuery select = new DBSelectQuery(context, db);
		DbUpdateQuery update = new DbUpdateQuery(context, db);
		
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("name", newName);
		
		ArrayList<MainSettingData> Mainlist = select.getMainSettingAssetToName(asset, name);
		
		for (int i = 0; i < Mainlist.size(); i++)
		{
			update.setMainSettingUpdate(map, Mainlist.get(i).getId());
		}
		
		ArrayList<AutoMainData> autoList = select.getAutoAssetList(asset, name);
		
		for (int i = 0; i < autoList.size(); i++)
		{
			update.setAutoMainUpdate(map, autoList.get(i).getId());
		}
		
		ArrayList<SmsData> smsList = select.getSmsAssetList(asset, name);
		
		for (int i = 0; i < smsList.size(); i++)
		{
			update.setSmsUpdate(map, smsList.get(i).getId());
		}
		
		ArrayList<HalbuData> halbuList = select.getHalbuAssetList(asset, name);
		
		for (int i = 0; i < halbuList.size(); i++)
		{
			update.setSmsUpdate(map, halbuList.get(i).getId());
		}
	}
}
